package com.ruizhong.PIW.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruizhong.PIW.dao.TStyleMapper;
import com.ruizhong.PIW.entity.TStyle;
import com.ruizhong.PIW.entity.TWindow;
import com.ruizhong.PIW.service.StyleService;
import com.ruizhong.PIW.service.WindowService;
import com.ruizhong.PIW.vo.StyleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class StyleServiceImpl extends ServiceImpl<TStyleMapper, TStyle> implements StyleService {

    @Autowired
    private WindowService windowService;

    @Override
    public StyleVO getStyleInfo(Integer styleId) {
        TStyle tStyle = getById(styleId);
        StyleVO styleVO = new StyleVO();
        styleVO.setStyleName(tStyle.getName());
        styleVO.setMaxIndex(tStyle.getMaxIndex());
        styleVO.setNewNodeNum(tStyle.getNewNodeNum());
        List<TWindow> tWindowList = windowService.getWindowsByStyleId(styleId);
        styleVO.setList(tWindowList);
        return styleVO;
    }

    @Override
    public List<Integer> getAllStyleId() {
        List<TStyle> list = lambdaQuery()
                .select(TStyle::getId)
                .list();
        List<Integer> styleIds =
                list
                        .stream()
                        .map(TStyle::getId)
                        .collect(Collectors.toList());
        return styleIds;
    }


}
